package net.neptech.controller;

import lombok.RequiredArgsConstructor;

import net.neptech.model.vo.OrgDataVo;
import net.neptech.model.vo.OrgSelectShowVo;
import net.neptech.service.OrgService;

import net.neptech.vm.ResponseResult;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Saya
 * @Date 2025/8/24 23:29
 * @Description TODO
 **/
@RestController
@RequestMapping(value = {"org"})
@RequiredArgsConstructor
public class OrgController {

    private final OrgService orgService;

    /**
     * 按层级查询组织架构树
     *
     * @param deptId    部门id
     * @param showLeave 是否显示离职员工
     * @return 组织架构树数据
     */
    @GetMapping("tree")
    public ResponseResult<OrgSelectShowVo> getOrgTreeData(@RequestParam(defaultValue = "0") String deptId, String type, @RequestParam(defaultValue = "false") Boolean showLeave) {
        return ResponseResult.success(orgService.getOrgTreeData(deptId, type, showLeave));
    }


    /**
     * 查询所有的组织架构树，不分层
     *
     * @return 组织架构树数据
     */
    @GetMapping("treeAll")
    public ResponseResult<List> getOrgTreeDataAll(String keywords, Integer status) {
        return ResponseResult.success(orgService.getOrgTreeDataAll(keywords, status));
    }

    /**
     * 模糊搜索用户
     *
     * @param userName 用户名/拼音/首字母
     * @return 匹配到的用户
     */
    @GetMapping("tree/user/search")
    public ResponseResult<List<OrgDataVo>> getOrgTreeUser(@RequestParam String userName) {
        return ResponseResult.success(orgService.getOrgTreeUser(userName));
    }
}
